using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using TenantManagementService.Monitoring;

namespace TenantManagementService.Monitoring
{
    /// <summary>
    /// 监控服务接口
    /// </summary>
    public interface IMonitoringService : IApplicationService
    {
        /// <summary>
        /// 记录监控指标
        /// </summary>
        Task RecordMetricAsync(string metricName, decimal value, Dictionary<string, string>? dimensions = null, Guid? tenantId = null);

        /// <summary>
        /// 记录租户指标
        /// </summary>
        Task RecordTenantMetricAsync(Guid tenantId, string metricName, decimal value, Dictionary<string, string>? dimensions = null);

        /// <summary>
        /// 批量记录指标
        /// </summary>
        Task RecordMetricsAsync(List<MetricRecordInput> metrics);

        /// <summary>
        /// 获取指标值
        /// </summary>
        Task<decimal?> GetMetricValueAsync(string metricName, DateTime? startTime = null, DateTime? endTime = null, Dictionary<string, string>? dimensions = null, Guid? tenantId = null);

        /// <summary>
        /// 获取指标历史数据
        /// </summary>
        Task<List<MetricDataPoint>> GetMetricHistoryAsync(string metricName, DateTime startTime, DateTime endTime, Dictionary<string, string>? dimensions = null, Guid? tenantId = null);

        /// <summary>
        /// 获取租户使用统计
        /// </summary>
        Task<TenantUsageStatistics> GetTenantUsageStatisticsAsync(Guid tenantId, DateTime? startTime = null, DateTime? endTime = null);

        /// <summary>
        /// 获取所有租户的概览统计
        /// </summary>
        Task<TenantsOverviewStatistics> GetTenantsOverviewStatisticsAsync();

        /// <summary>
        /// 获取租户资源使用情况
        /// </summary>
        Task<List<TenantResourceUsage>> GetTenantResourceUsageAsync(List<Guid> tenantIds = null);

        /// <summary>
        /// 检查告警规则
        /// </summary>
        Task CheckAlertRulesAsync();

        /// <summary>
        /// 创建告警规则
        /// </summary>
        Task<AlertRuleDto> CreateAlertRuleAsync(CreateAlertRuleInput input);

        /// <summary>
        /// 更新告警规则
        /// </summary>
        Task<AlertRuleDto> UpdateAlertRuleAsync(Guid id, UpdateAlertRuleInput input);

        /// <summary>
        /// 删除告警规则
        /// </summary>
        Task DeleteAlertRuleAsync(Guid id);

        /// <summary>
        /// 获取告警规则列表
        /// </summary>
        Task<PagedResultDto<AlertRuleDto>> GetAlertRulesAsync(GetAlertRulesInput input);

        /// <summary>
        /// 获取活跃告警列表
        /// </summary>
        Task<PagedResultDto<AlertDto>> GetActiveAlertsAsync(GetActiveAlertsInput input);

        /// <summary>
        /// 处理告警
        /// </summary>
        Task<AlertDto> HandleAlertAsync(Guid id, HandleAlertInput input);

        /// <summary>
        /// 忽略告警
        /// </summary>
        Task<AlertDto> IgnoreAlertAsync(Guid id, string reason);

        /// <summary>
        /// 获取告警统计
        /// </summary>
        Task<AlertStatistics> GetAlertStatisticsAsync(DateTime? startTime = null, DateTime? endTime = null, Guid? tenantId = null);

        /// <summary>
        /// 获取系统健康状态
        /// </summary>
        Task<SystemHealthStatus> GetSystemHealthStatusAsync();
    }
}